<!DOCTYPE html>
<html>
<title>数值方法</title>

<body>

    <script>
        var num = 12.5;
        document.write("原数:" + num + "<br>");
        document.write(num.toExponential() + "<br>"); // 返回 1.25e+1
        document.write(num.toExponential(2) + "<br>"); // 返回 1.25e+1
        document.write(num.toExponential(4) + "<br>"); // 返回 1.2500e+1
        document.write(num.toExponential(6) + "<br><hr>"); // 返回 1.250000e+1

        num = 12.525;
        document.write("原数:" + num + "<br>");
        document.write(num.toFixed() + "<br>");
        document.write(num.toFixed(2) + "<br>");
        document.write(num.toFixed(4) + "<br>");
        document.write(num.toFixed(6) + "<br><hr>");

        num = 5.123456;
        document.write("原数:" + num + "<br>");
        document.write(num.toPrecision() + "<br>");
        document.write(num.toPrecision(1) + "<br>");
        document.write(num.toPrecision(2) + "<br>");
        document.write(num.toPrecision(3) + "<br>");
        document.write(num.toPrecision(4) + "<br>");
        document.write(num.toPrecision(10) + "<br><hr>");

        //toString 没啥好说的 正着是返回进制，倒着是变成字符串
        //Number(x)字符串转数字,true是1，false是0
        //parseInt()解析一个字符串，返回一个整数,是第一个字符
        document.write("12" + parseInt("12") + "<br>");
        document.write("12.25" + parseInt("12.25") + "<br>");
        document.write("15px" + parseInt("15px") + "<br>");
        document.write("4 days" + parseInt("4 days") + "<br>");
        document.write("Day 4" + parseInt("Day 4") + "<br>");
        document.write("36 24 36" + parseInt("36 24 36") + "<br>");
        document.write("   20   " + parseInt("   20   ") + "<br>");
        //parseInt(n,16)代表把n转成16进制
        document.write("36 24 36" + parseInt("36 24 36", 16) + "<br><hr>");
        //parseFloat差不多
        document.write("12" + parseFloat("12") + "<br>");
        document.write("12.25" + parseFloat("12.25") + "<br>");
        document.write("80.5px" + parseFloat("80.5px") + "<br><hr>");
        document.write("最大值和最小值<br>");
        var num1 = Number.MAX_VALUE;
        var num2 = Number.MIN_VALUE;
        document.write(num1 + "<br>" + num2);
    </script>

</body>

</html>